#version 150

struct Light
{
	vec3 pos;
	float power;
	vec3 color;
};

const int MAX_LIGHTS = 4;

in vec3 position;
in vec2 texcoord;
in vec3 normal;
in vec3 tangent;
in vec3 bitangent;

out vec2 Texcoord;
out vec3 VertexPos_World;
out float Depth;
out vec3 EyeDir_Tan;
out vec3 LightDir_Tan[MAX_LIGHTS];


uniform float FCP;
uniform int lightCount;
uniform Light lights[MAX_LIGHTS];
uniform mat4 model;
uniform mat4 view;
uniform mat4 modelView;
uniform mat4 modelViewProj;

void main() 
{
	gl_Position = modelViewProj * vec4(position, 1.0);
	Texcoord = texcoord;	
	VertexPos_World = (model * vec4(position, 1.0)).xyz;
	Depth = gl_Position.z / FCP;
	
	vec3 normal_Cam = (modelView * vec4(normal, 0.0)).xyz;
	vec3 tangent_Cam = (modelView * vec4(tangent, 0.0)).xyz;
	vec3 bitangent_Cam = (modelView * vec4(bitangent, 0.0)).xyz;
		
	mat3 TBN = transpose(mat3(tangent_Cam, bitangent_Cam, normal_Cam));
	
	vec3 vertexPos_Cam = (modelView * vec4(position, 1.0)).xyz;
	vec3 eyeDir_Cam = vec3(0.0, 0.0, 0.0) - vertexPos_Cam;
	EyeDir_Tan = TBN * eyeDir_Cam;
	
	for (int i = 0; i < lightCount; ++i)
	{
		vec3 lightPos_Cam = (modelView * vec4(lights[i].pos, 1.0)).xyz;
		vec3 lightDir_Cam = lightPos_Cam - vertexPos_Cam;	
		LightDir_Tan[i] = TBN * lightDir_Cam;
	}	
}